package com.huawei.M01.iterator;

/**
 * @author 12
 */
public class LatestRepeat {
    public int reinitializePermutation(int n) {
        int[] arr = new int[n];
        int[] perm = new int[n];
        for (int i = 0; i < perm.length; i++) {
            perm[i] = i;
        }
        int res = 0;
        while (true) {
            res++;
            for (int i = 0; i < arr.length; i++) {
                if (i % 2 == 0) {
                    arr[i] = perm[i / 2];
                } else {
                    arr[i] = perm[n / 2 + (i - 1) / 2];
                }
            }
            perm = arr;
            if (arr[1] == 1) {
                break;
            }
            arr = new int[n];
        }
        return res;
    }

    public static void main(String[] args) {
        LatestRepeat latestRepeat = new LatestRepeat();
        System.out.println(latestRepeat.reinitializePermutation(6));
    }
}
